﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.ModularFixture.CApMFMappingReportUtils
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using System;
using System.Collections;
using System.Collections.ObjectModel;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.Utilities;
using Tecnomatix.Planning;


namespace DnProcessSimulateCommands.ModularFixture;

internal class CApMFMappingReportUtils
{
  internal const string CONFIGURATION_PROTOTYPE_ID = "ConfigurationPrototypeId";
  internal const string LOCATING_POINT_ATTRIBUTE = "LocatingPoint";
  internal const string VALID_SOLUTION_ATTRIBUTE = "ValidSolution";
  internal const string CONFIGURATION_PROTOTYPE_USAGE = "Usage";
  internal const string PLP_TYPE = "PmPLP";
  internal const string PLP_USAGE_TYPE = "PmPLPUsage";
  internal const string OPERATION_TYPE = "PmOperation";
  internal const string CHILDREN_FIELD = "children";
  internal const string MFG_USAGES_FIELD = "mfgUsages";
  internal const string TOOL_TYPE_FIELD = "toolType";
  internal const string PLP_USAGE_USES_FIELD = "uses";
  internal const string CONFIGURATION_PROTOTYPE_CLASS_NAME = "UnitConfigurationPrototype";
  internal const string CONFIGURATION_TYPE_FIELD = "ConfigurationType";
  internal const string CONFIGURATION_VALUE = "Configuration";

  internal static ITxPlanningObject GetPlanningRepresentation(ITxObject obj)
  {
    switch (obj)
    {
      case ITxProcessModelObject processModelObject:
        pattern_0 = processModelObject.PlanningRepresentation;
        break;
    }
    return pattern_0;
  }

  internal static int GetInternalIdFromExternalId(string externalId)
  {
    int idFromExternalId = 0;
    ITxPlanningObject objectFromExternalId = CApMFMappingReportUtils.GetPlanningObjectFromExternalId(externalId);
    if (objectFromExternalId != null)
      idFromExternalId = (objectFromExternalId.PlatformServicesProvider as TxEmsServicesProvider).InternalId;
    return idFromExternalId;
  }

  internal static ITxPlanningObject GetPlanningObjectFromExternalId(string externalId)
  {
    ITxPlanningObject objectFromExternalId = (ITxPlanningObject) null;
    if (externalId != null)
      objectFromExternalId = new TxEmsGlobalServicesProvider().GetObjectByProcessModelId(new TxProcessModelId(externalId));
    return objectFromExternalId;
  }

  internal static void CacheData(TxObjectList rootList, string category, params string[] fields)
  {
    TxEmsCacheManager txEmsCacheManager = new TxEmsCacheManager();
    TxObjectList txObjectList = new TxObjectList();
    foreach (ITxObject root in (Collection<ITxObject>) rootList)
    {
      ITxPlanningObject planningRepresentation = CApMFMappingReportUtils.GetPlanningRepresentation(root);
      if (planningRepresentation != null)
        ((Collection<ITxObject>) txObjectList).Add((ITxObject) planningRepresentation);
    }
    if (((Collection<ITxObject>) txObjectList).Count <= 0 || fields == null)
      return;
    txEmsCacheManager[category].RootObjects = txObjectList;
    txEmsCacheManager[category].SetAttributes(fields);
    txEmsCacheManager.CacheData();
  }

  internal static bool ImportFields(
    TxObjectList roots,
    ArrayList fieldsToCollect,
    ArrayList fieldsToTraverse)
  {
    bool flag = true;
    if (roots != null)
    {
      if (((Collection<ITxObject>) roots).Count > 0)
      {
        try
        {
          TxObjectList txObjectList = new TxObjectList();
          foreach (ITxObject root in (Collection<ITxObject>) roots)
          {
            if (root != null && root.IsValid())
            {
              ITxPlanningObject planningRepresentation = CApMFMappingReportUtils.GetPlanningRepresentation(root);
              if (planningRepresentation != null)
                ((Collection<ITxObject>) txObjectList).Add((ITxObject) planningRepresentation);
            }
          }
          if (((Collection<ITxObject>) txObjectList).Count > 0)
          {
            TxEmsImportFieldsData importFieldsData = new TxEmsImportFieldsData();
            importFieldsData.Roots = txObjectList;
            if (fieldsToCollect != null && fieldsToCollect.Count > 0)
              importFieldsData.addFieldsToCollect(fieldsToCollect);
            if (fieldsToTraverse != null && fieldsToTraverse.Count > 0)
              importFieldsData.addFieldsToTraverse(fieldsToTraverse);
            (TxApplication.ActiveDocument.PlatformGlobalServicesProvider as TxEmsGlobalServicesProvider).ImportFields((TxPlatformImportFieldsData) importFieldsData);
          }
        }
        catch (Exception ex)
        {
          flag = false;
        }
      }
    }
    return flag;
  }

  internal static TxClassFieldsCollectionData GetCollectionData(
    string className,
    params string[] fieldNames)
  {
    TxClassFieldsCollectionData collectionData = new TxClassFieldsCollectionData();
    collectionData.ClassName = className;
    ArrayList arrayList = new ArrayList();
    if (fieldNames != null)
    {
      foreach (string fieldName in fieldNames)
      {
        if (!arrayList.Contains((object) fieldName))
          arrayList.Add((object) fieldName);
      }
    }
    collectionData.FieldNames = arrayList;
    return collectionData;
  }

  internal static TxClassFieldsTraversalData GetTraversalData(
    string className,
    params string[] fieldNames)
  {
    TxClassFieldsTraversalData traversalData = new TxClassFieldsTraversalData();
    traversalData.ClassName = className;
    ArrayList arrayList = new ArrayList();
    if (fieldNames != null)
    {
      foreach (string fieldName in fieldNames)
      {
        if (!arrayList.Contains((object) fieldName))
          arrayList.Add((object) fieldName);
      }
    }
    traversalData.FieldNames = arrayList;
    return traversalData;
  }

  internal enum EDataStatus
  {
    dataValid,
    dataInvalid,
    dataNotLoaded,
  }
}
